package jp.co.baka.pachinko.util;

import org.slim3.controller.ControllerConstants;
import org.slim3.controller.validator.Errors;
import org.slim3.util.RequestLocator;


public class LogicalErrors{


    private LogicalErrors(){

    }

    /**
     * エラーメッセージの追加
     *
     * @param message
     */
    public static void addErrMessage(String message){

        Errors errors = (Errors)RequestLocator.get().getAttribute(ControllerConstants.ERRORS_KEY);
        if(errors==null || errors.isEmpty()){
            errors = new Errors();
        }

        errors.put(String.valueOf(errors.size()),message);
        RequestLocator.get().setAttribute(ControllerConstants.ERRORS_KEY, errors);

    }

    /**
     * エラーがあるかどうか
     *
     * @return
     */
    public static boolean hasErrors(){
        Errors errors = (Errors)RequestLocator.get().getAttribute(ControllerConstants.ERRORS_KEY);
        if(errors==null || errors.isEmpty()){
            return false;
        }else{
            return true;
        }
    }
}
